<?php

class AdminPetsController extends AdminAppController {
	
	public $name = 'Pets';
	
	public $uses = array('Pet');
	
	public function index() {
		$this->Pet->recursive = 0;
		$this->paginate = array (
			'order' => array('Pet.id' => 'desc')
		);
		$this->set('pets', $this->paginate('Pet'));
	}
	
	public function create() {
		if( $this->request->is('post') ) {
			
			//$this->request->data['Picture']['group'] = 'product';
			$this->Pet->create();
			if( $this->Pet->save( $this->request->data ) ) {
				$this->setUserInfo(__d('admin', 'The Pet has been created.'), 'success');
				$this->redirect(array('action' => 'index'));
			}
			else {
				$this->log('Error creating Pet: ' . print_r($this->Pet->validationErrors, true));
				$this->setUserInfo(__d('admin', 'The Pet could not be saved. Please, try again.'), 'error');
			}
		}
		
		$this->set('users', $this->Pet->User->find('list', array('order' => array('User.first_name', 'User.last_name'))));
	}
	
}